<!-- 待处理收文 -->
<template>
  <view>
    <van-pull-refresh v-model="refreshing" @refresh="onRefresh">
      <van-list v-model="loading" :finished="finished" finished-text="没有更多了" @load="load_more"
                offset="20" :error.sync="error" error-text="请求失败，点击重新加载">
        <van-cell center v-for="item in list" :title="item.TITLE"
                  :label="'来文号：' + (item.FILE_SIZE==null?'':item.FILE_SIZE)"
                  @click="toDoReceive(item)" value-class="text-sm" class="content">
          <template #title>
						<span class="content-title">
              <i class="iconfont icon-gongwenshouwen content-blue"></i>{{ item.TITLE }}
            </span>
            <van-tag class="content-tag" plain v-if="item.URGENCYNAME != null && item.URGENCYNAME != ''"
                     :type="item.URGENCYNAME != '平件' ? 'danger' : 'primary'">
              {{ item.URGENCYNAME }}
            </van-tag>
          </template>
          <template #label>
            <span class="content-label">
              来文号：{{ item.FILE_SIZE == null ? '' : item.FILE_SIZE }}
            </span>
          </template>
          <template #extra>
            <span class="content-span">{{ dateFormat(item.CREATE_TIME) }}</span>
          </template>
        </van-cell>
      </van-list>
    </van-pull-refresh>
  </view>
</template>

<script>
export default {
  data() {
    return {
      list: [],
      loading: false,   // 加载状态
      finished: false,  // 是否加载
      refreshing: false,// 是否刷新
      error: false,     // 错误状态
      pageNum: 1,   // 页数
      pageSize: 10, //条数

    }
  },

  mounted() {

  },

  methods: {
    // 下拉刷新
    onRefresh() {
      // 先清空数据
      this.list = []
      // 将 loading 设置为 true，表示处于加载状态
      this.loading = true
      // 将没有更多的状态改成false
      this.finished = false
      // 默认加载第一页
      this.pageNum = 1
      this.getList()
      this.refreshing = false
    },

    // 上拉加载
    load_more() {
      // 页数设置
      if (this.list.length == 0) {
        this.pageNum = 1
      } else {
        this.pageNum++
      }
      // 将下拉刷新停止
      this.refreshing = false;
      // 加载状态
      this.loading = true
      this.getList()
    },

    // 获取待处理收文数据
    async getList() {
      await this.$http({
        url: this.$http.adornUrl(`/caac/oa/doc/fwend/getSwListData`),
        method: 'get',
        params: this.$http.adornParams({
          'systemKey': this.cache.get('userInfo').systemKey,
          'systemFlag': this.cache.get('userInfo').systemFlag,
          'ACCEPT_TYPE': 'IS NULL',
          'ACCEPT_DEPT': this.cache.get('userInfo').mainDept.deptCode,
          'page': this.pageNum,
          'rows': this.pageSize
        })
      }).then(({data}) => {
        if (data.code == 200) {
          if (data.data != null && JSON.stringify(data.data) != '{}') {
            if (this.pageNum == 1) {
              this.list = data.data.rows
            } else {
              data.data.rows.forEach(t => this.list.push(t))
            }
            // 关闭加载状态
            this.loading = false
            // 判断当前页是否为最后一页
            if ((this.pageNum * this.pageSize) > data.data.total) {
              this.finished = true
            }
          } else {
            this.finished = true
          }
        } else {
          this.loading = false;//将加载状态关掉
          this.error = true;//大家错误状态
        }
      })
    },

    // 时间格式化
    dateFormat(dateTime) {
      let formatStr = dateTime
      if (dateTime != null && dateTime != '' && dateTime.length > 10) {
        formatStr = dateTime.substr(0, 10)
      }
      return formatStr
    },

    // 跳转收文处理
    toDoReceive(item) {
      let bizId = item.BIZ_ID
      let uuId = item.UUID
      uni.navigateTo({
        url: "/pages/caac/receive/todoDocDetail?bizId=" + bizId + '&uuId=' + uuId
      })
    },
  },
}
</script>

<style>
	.van-cell__title {
		min-width: 50%;
	
		span {
			display: inline-block;
			text-align: left;
			word-break: break-all;
		}
	}
  .content {
    padding: 30rpx;
  }
  .content-title {
    padding: 10rpx 20rpx 10rpx 0rpx;
  }
  .content-blue {
    color: #1296db;
    padding-right: 10rpx;
    font-size: 36rpx;
  }
  .content-label {
    padding-left: 40rpx;
  }

  .content-span {
    font-size: 24rpx;
  }
</style>
